﻿<#include "common/top.html"/>
<@shiro.hasPermission name="shanghujiaosetianjia">
<div class="layui-form-item layui-form-item-top">
	<button class="layui-btn-tan" id="addRole">
		<i class="layui-icon">&#xe608;</i> 添加
	</button>
</div>

</@shiro.hasPermission>
<form class="layui-form" action="${basePath}merchant/mcrole/getRolelistPage" type="0" method="post" name="userForm" id="userForm">
<@shiro.hasPermission name="shanghujiaosechaxun">
    <div class="searchbox" id="searchbox">
		<input type="text" name="keywords" value="${pd.keywords}" lay-verify="title" autocomplete="off" placeholder="请输入关键字" class="layui-input">

        <input type="button" value="查询" onclick="searchs();" class="layui-btn layui-btn-red"/>
    </div>
</@shiro.hasPermission>
    <div class="levTable">
        <table id="simple-table" class="table table-striped table-bordered table-hover">
            <thead>
            <tr>
                <th>序号</th>
                <th>角色名称</th>
                <th>描述</th>
                <th style="width: 100px;">操作</th>
            </tr>
            </thead>
            <tbody>
            <#if "${roleList?has_content}">
                <#list  roleList as var >
                    <tr>
                        <td>${var_index?if_exists+1}</td>
                     <#--   <#assign comCode= var.comCode />-->
                        <td>${var.roleName }</td>
                        <#--<td>${var.roleCode?replace(comCode,'') }</td>-->
                        <td>${var.descb}</td>
                        <td>
                             <@shiro.hasPermission name="shouquanjiaose">
                            <a style="font-size: 17px;" class="layui-icon" onclick="editRights('${var.roleId }');"
                               title="菜单权限">&#xe612;</a>
                                </@shiro.hasPermission>
                            <@shiro.hasPermission name="shanghujiaosexiugai">
                            <a class="layui-icon" onclick="editRole('${var.roleId }');" title="修改">&#xe642;</a>
                            </@shiro.hasPermission>
                            <@shiro.hasPermission name="shanghujiaoseshanchu">
                            <a class="layui-icon" onclick="delRole('${var.roleId }');" title="删除">&#xe640;</a>
                            </@shiro.hasPermission>
                        </td>
                    </tr>
                </#list>
            </#if>
            </tbody>
        </table>
    </div>

	<#include "/common/page.html" />
</form>
<script type="text/javascript">
    var rooturl = "${basePath}merchant/mcrole/getRolelistPage";
    //检 索
    function searchs() {
        _GLOBE_DATA("reLoadPageParam")(_GLOBE_DATA("createURL")(rooturl, "searchbox"));
    }

    //修改
    function editRole(roleId) {
        layer.open({
            type: 2,//此处以iframe举例
            title: '角色编辑',
            area: ['450px', '450px'],
            maxmin: true,
            content: '${basePath}merchant/mcrole/toRoleEdit?roleId=' + roleId,
            btn: ['保存', '关闭'], //只是为了演示
            yes: function (index, layero) {
                var iframeWin = window[layero.find('iframe')[0]['name']];
                iframeWin.save();
            },
            no: function (index) {
                layer.close(index);
            },
            end: function () {
                reLoadPage(rooturl);
            }
        });
    }

    //删除
    function delRole(roleId) {
        layer.confirm('确认要删除吗？', {
            btn: ['确定', '取消']
        }, function (index, layero) {
            var url = "${basePath}merchant/mcrole/deleteRole?roleId=" + roleId;
            $.ajax({
                url: url,
                type: "POST",
                success: function (data) {
                    if (data.status == 'success') {
                        layer.alert(data.msg, function (index) {
                            var index1 = parent.layer.getFrameIndex(window.name); //获取窗口索引
                            parent.layer.close(index1);
                            parent.layer.close(index);
                            reLoadPage(rooturl);
                        });
                    } else {
                        layer.alert(data.msg);
                    }
                }
            })
        });
    }

    //菜单权限
    function editRights(roleId) {
        layer.open({
            type: 2,//此处以iframe举例
            title: '菜单权限',
            area: ['500px', '400px'],
            maxmin: true,
            content: '${basePath}/merchant/shanghumenu/listmenus?roleId=' + roleId,
            btn: ['保存', '关闭'],
            yes: function (index, layero) {
                var iframeWin = window[layero.find('iframe')[0]['name']];
                iframeWin.save();
            },
            no: function (index) {
                layer.close(index);
            },
            end: function () {
                reLoadPage(rooturl);
            }
        });

    }
    //添加
    $("#addRole").click(function () {
        layer.open({
            type: 2,//此处以iframe举例
            title: '角色添加',
            area: ['450px', '450px'],
            maxmin: true,
            content: '${basePath}merchant/mcrole/toRoleEdit',
            btn: ['保存', '关闭'], //只是为了演示
            yes: function (index, layero) {
                var iframeWin = window[layero.find('iframe')[0]['name']];
                iframeWin.save();
            },
            no: function (index) {
                layer.close(index);
            },
            end: function () {
                reLoadPage(rooturl);
            }
        });
    });
</script>
